<template>
    <div class="app-container">

        <SearchContent :queryParams="queryParams" @query="handleQuery" @reset="resetQuery">

            <el-col :span="6">
                <el-form-item label="司机姓名:" prop="driverName">
                    <el-input maxlength="30" v-model="queryParams.driverName" clearable
                              placeholder="请输入司机姓名"></el-input>
                </el-form-item>
            </el-col>

            <el-col :span="6">
                <el-form-item label="所在城市:" prop="cityName">
                    <el-input maxlength="30" v-model="queryParams.cityName" clearable
                              placeholder="请输入城市名称"></el-input>
                </el-form-item>
            </el-col>

            <el-col :span="6">
                <el-form-item label="所属公司:" prop="belongCompanyName">
                    <el-input maxlength="30" v-model="queryParams.belongCompanyName" clearable
                              placeholder="请输入公司名称"></el-input>
                </el-form-item>
            </el-col>

            <el-col :span="6">
                <el-form-item label="服务客户:" prop="serviceName">
                    <el-input maxlength="30" v-model="queryParams.serviceName" clearable
                              placeholder="请输入客户名称"></el-input>
                </el-form-item>
            </el-col>

        </SearchContent>

        <div class="card-wrap card-padding" :model="queryParams">
            <div class="table-title-wrap justify-end">
                <el-button type="primary" size="mini" @click="handleAdd"
                           v-hasPermi="['driverManage:laberCompany:add']">新增
                </el-button>
                <el-button type="success" size="mini" @click="handleExport"
                           v-hasPermi="['driverManage:laberCompany:export']">导出
                </el-button>
                <el-button type="warning" size="mini" @click="handleImport"
                           v-hasPermi="['driverManage:laberCompany:batchadd']">导入
                </el-button>
            </div>

            <table-page :loading="loading" :dataList="dataList" border :total="total" :page.sync="queryParams.pageNum"
                        :limit.sync="queryParams.pageSize" @setSizeCurrent="getList">
                <!-- 操作插槽 -->
                <template slot="tableColAc">
                    <el-table-column label="操作" min-width="130" align="center" class-name="small-padding fixed-width">
                        <template slot-scope="scope">
                            <e-button size="mini" type="text" @click="handleUpdate(scope.row)"
                                      v-if="0==scope.row.approvalStatus||3==scope.row.approvalStatus||4==scope.row.approvalStatus"
                                      v-hasPermi="['driverManage:laberCompany:edit']">编辑
                            </e-button>
                            <e-button size="mini" type="text" @click="handleDelete(scope.row)"
                                      v-if="(0==scope.row.approvalStatus||2==scope.row.approvalStatus||3==scope.row.approvalStatus||4==scope.row.approvalStatus) && 0==scope.row.delStatus"
                                      v-hasPermi="['driverManage:laberCompany:delete']">删除
                            </e-button>
                            <e-button size="mini" type="text" @click="handleDetail(scope.row)"
                                      v-hasPermi="['driverManage:laberCompany:view']">查看
                            </e-button>
                        </template>
                    </el-table-column>
                </template>
                <!-- 普通列插槽 -->
                <template slot="tableCol">
                    <el-table-column min-width="210" show-overflow-tooltip label="司机编码" align="center" prop="driverCode">
                        <template v-slot="scope">
                            {{ scope.row.driverCode|filterNull }}
                        </template>
                    </el-table-column>
                    <el-table-column min-width="130" show-overflow-tooltip label="司机姓名" align="center" prop="driverName">
                        <template v-slot="scope">
                            {{ scope.row.driverName|filterNull }}
                        </template>
                    </el-table-column>
                    <el-table-column min-width="130" show-overflow-tooltip label="所属公司" align="center" prop="belongCompanyName">
                        <template v-slot="scope">
                            {{ scope.row.belongCompanyName|filterNull }}
                        </template>
                    </el-table-column>
                    <el-table-column min-width="100" show-overflow-tooltip label="审批状态" align="center" prop="approvalStatus">
                        <!--            0.待审批，1.审批中，2审批通过，3审批拒绝  -->
                        <template v-slot="scope">
                            <dict-tag
                                :options="dict.type.approval_status"
                                :value="scope.row.approvalStatus"
                            />
                        </template>
                    </el-table-column>
                    <el-table-column min-width="100" show-overflow-tooltip label="所在城市" align="center" prop="cityName">
                        <template v-slot="scope">
                            {{ scope.row.cityName|filterNull }}
                        </template>
                    </el-table-column>
                    <el-table-column min-width="130" show-overflow-tooltip label="联系电话" align="center" prop="driverPhone">
                        <template v-slot="scope">
                            {{ scope.row.driverPhone|filterNull }}
                        </template>
                    </el-table-column>
                    <el-table-column min-width="130" show-overflow-tooltip label="服务客户名称" align="center" prop="serviceName">
                        <template v-slot="scope">
                            {{ scope.row.serviceName|filterNull }}
                        </template>
                    </el-table-column>
                </template>
            </table-page>
        </div>

    </div>
</template>

<script>

import SearchContent from "@/components/SearchContent/index.vue";
import {
    driverList,
    driverDelete,
    driverCompanyList,
    IMPORTDRIVER,
    TEMPLATEDRIVER,
    ERRORDRIVER
} from "@/api/memberManage/driverList";
import {supplierDelete} from "@/api/memberManage/vendorList";
import {CUSTOMER_EXPORT, IMPORTMEMBER} from "@/api/memberManage/memberList";


export default {
    name: "DriverList",
    components: {
        SearchContent
    },
    dicts: ['approval_status'],
    data() {
        return {
            //按钮loading
            buttonLoading: false,
            // 遮罩层
            loading: true,
            isNew: true,
            // 弹出层标题
            title: "",

            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                driverName: null,
                cityName: null,
                belongCompanyName: null,
                serviceName: null,
            },

            total: 0,
            dataList: [],
        };
    },
    created() {
        this.getList()
    },
    activated() {
        this.getList()
    },
    methods: {
        /** 查询测试单表列表 */
        getList() {
            this.loading = true;


            driverList(this.queryParams).then(res => {
                if (res.code == "200") {
                    const {rows, total} = res
                    this.dataList = rows
                    this.total = total
                    this.loading = false;
                }

            });
        },

        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },

        /** 重置按钮操作 */
        resetQuery() {
            this.queryParams = {
                pageNum: 1,
                pageSize: 10,
                driverName: null,
                cityName: null,
                belongCompanyName: null,
                serviceName: null,
            },
                // this.resetForm("queryForm");
                this.handleQuery();
        },

        /** 新增操作 */
        handleAdd() {

          // this.$router.push({
          this._toPage({
                name: 'driverAdd',
                query: {type: 'write', pageType: '新增司机'}
            })

        },

        handleDetail(row) {
          // this.$router.push({
          this._toPage({
                name: 'driverDetail',
                query: {driverId: row.driverId, type: 'readonly', pageType: '司机详情'}
            })
        },

        /** 修改按钮操作 */
        handleUpdate(row) {
          // this.$router.push({
          this._toPage({
                name: 'driverAdd',
                query: {driverId: row.driverId, type: 'write', pageType: '编辑司机'}
            })
        },

        /** 导出按钮操作 */
        handleExport() {
            this.download('/driver/driver/export', {
                ...this.queryParams
            }, `司机列表.xlsx`)
        },
        /** 导入按钮操作 */
        handleImport() {
            this.$UploadDialog({
                title: "导入司机",
                showtoastSureBtn: false,
                showResult: true,
                showErrorFeedback: false,
                uploadConfig: {
                    uploadFileUrl: `#${IMPORTDRIVER}`,
                    limit: 1,
                    params: {},
                    fileType: ['xls', 'xlsx'],
                    templateUrl: `${TEMPLATEDRIVER('driver_export')}`,
                    templateName: `司机-导入模版.xlsx`,
                },
            }).finally(f => {
                this.handleQuery()
            })

        },

        /** 删除按钮操作 */
        handleDelete(row) {
            // this.$modal.confirm('确定删除？').then(() => {
            //   this.loading = true;
            //   return driverDelete(row.driverId);
            // }).then(() => {
            //   this.loading = false;
            //   this.handleQuery();
            //   this.$modal.msgSuccess("删除已提交");
            // }).finally(() => {
            //   this.loading = false;
            // });

            this.$prompt('删除理由', '确定删除?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPlaceholder: "删除理由为必填项",
                inputPattern: /^(?!\s+$).{1,500}$/,
                inputErrorMessage: '备注不能为空且不能大于500字'
            }).then(({value}) => {
                this.loading = true;
                return driverDelete({driverIds: row.driverId, delRemark: value});
            }).then(() => {
                this.loading = false;
                this.handleQuery();
                this.$modal.msgSuccess("删除已提交");
            }).finally(() => {
                this.loading = false;
            });
        },

    }
};
</script>


<style lang="scss" scoped>
.pagination-container {
    padding: 0 20px 50px !important;
}


.form-dialog {
    ::v-deep .el-dialog__header {
        padding: 10px 20px;
        border-bottom: 1px solid #DCDFE6;

        .el-dialog__headerbtn {
            top: 15px;
        }
    }

    .box-card {
        margin-bottom: 20px;

        .card-title {
            font-size: 16px;
            position: relative;
            margin-left: 8px;
            padding: 0;
        }

        .card-title::after {
            content: '';
            width: 4px;
            height: 18px;
            background-color: aqua;
            display: block;
            position: absolute;
            left: -12px;
            top: 2px;
        }
    }

}
</style>
